home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / misc~1 / 5 / osspascl / char.doc < prev    next >
Encoding:
Text File  |  1985-11-19  |  7.6 KB  |  215 lines

  1.  
  2.  
  3.  
  4. Character I/O                                                           Page 1
  5.  
  6.                           Character Input and Output
  7.  
  8. The  ST  supports  five  character  oriented devices.  Of these five, you will
  9. probably only use four, the printer port, the RS232 port, the MIDI  port,  and
  10. the  keyboard/console.   The  other  device  is  the internal data path to the
  11. intelligent keyboard unit (which handles the mouse and joysticks, as  well  as
  12. the keyboard); you will seldom, if ever, need to access that device directly!
  13.  
  14. One  of  the most common operations on character oriented devices is reading a
  15. single character.  The following few routines perform that function:
  16.  
  17. Read character from standard input.
  18.  
  19. FUNCTION conin : Long_Integer ;
  20.   GEMDOS( 1 ) ;
  21.  
  22. This call waits for a character to be typed from  the  standard  input  device
  23. (normally  the  keyboard),  echoes  it  to  the  standard output (normally the
  24. screen), and returns the character thus read in the same manner as the  bconin
  25. BIOS  call.   This  call  should only be used from a TOS application.  You can
  26. also get a character from the standard input by Reading  characters  from  the
  27. standard  file  Input,  which  is  equivalent to using this routine.  In fact,
  28. unless you have a real need to use the routines described here, it is  usually
  29. better to use built-in Pascal methods.
  30.  
  31. Get a character from the auxilliary (RS232) device.
  32.  
  33. FUNCTION auxin : Integer ;
  34.   GEMDOS( 3 ) ;
  35.  
  36. If  you  want  characters  from the RS232 device, use this routine.  Since the
  37. characters returned by this call are only 8 bits, the return value is only  an
  38. Integer.
  39.  
  40. Get character from character-oriented device.
  41.  
  42. This  next  routine  is  the underlying BIOS call which can be used to perform
  43. input from any of the five devices.  You should normally use one of the  above
  44. GEMDOS  calls  whenever  possible,  but if you need to get input from the MIDI
  45. port, for example, you will need this routine:
  46.  
  47. FUNCTION bconin( device : Integer ) : Long_Integer ;
  48.   BIOS( 2 ) ;
  49.  
  50. This function  returns  a  character  from  the  specified  character-oriented
  51. device.  The valid values for the device parameter are as follows:
  52.  
  53. 0  printer port (not used for input)
  54. 1  RS232 port
  55. 2  keyboard
  56. 3  MIDI port
  57. 4  intelligent keyboard (don't use!)
  58.  
  59. If no character was waiting when bconin was called, it waits until a character
  60. is  available.   If  you  don't  want  to wait for characters, you should call
  61. bconstat  first,  to  determine  that   a   character   is   available.    The
  62. bconin  function  returns  the character value in the low byte of the returned
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. Character I/O                                                           Page 2
  71.  
  72. Long_Integer.  If the specified device is the console (device 2), however, the
  73. return value is more complex.  In that case, the keyboard scancode is returned
  74. in the upper word, and the ASCII equivalent (if any) is returned in the  lower
  75. word.
  76.  
  77. If  you  only  want  the Integer return value, and you want to assign it to an
  78. Integer variable, remember that you must use  the  built-in  function  Int  to
  79. convert from a Long_Integer to an Integer.
  80.  
  81.  
  82.  
  83. You  may  wish to find out whether a character is available before calling one
  84. of the character input routines.  Just as we  saw  above,  there  are  several
  85. calls designed to get that status:
  86.  
  87. Get status of standard input.  Don't use this one!!!
  88.  
  89. FUNCTION c_conis : boolean ;
  90.   GEMDOS( 11 ) ;
  91.  
  92. This routine is supposed to return True if at least one character is available
  93. on  the standard input device (normally the keyboard).  If the keyboard buffer
  94. ever gets  full,  however,  this  routine  ceases  to  work  properly,  always
  95. returning True.  For this reason, we recommend you use the bconstat BIOS call,
  96. instead.
  97.  
  98. Get status of auxilliary (RS232) port.
  99.  
  100. FUNCTION auxstat : Boolean ;
  101.   GEMDOS( 18 ) ;
  102.  
  103. This  call returns True, if at least one character is ready for input from the
  104. RS232 port, and False, otherwise.
  105.  
  106. If you need to get the input status of the MIDI port or the keyboard  (because
  107. of  the  bug  in  constat,  above), you will have to use the following routine
  108. which is the underlying BIOS call:
  109.  
  110. Character-oriented device input status
  111.  
  112. FUNCTION bconstat( device : Integer ) : Boolean ;
  113.   BIOS( 1 ) ;
  114.  
  115. This function expects the number of a character oriented device, as  described
  116. above (0-4).  It returns a True value if at least one character is waiting for
  117. input  and  False  otherwise.  If the device is the printer, however, there is
  118. one situation where the returned status will not be correct.  You  might  want
  119. to  define  your  own  special-purpose status routine as follows, so you don't
  120. have to insert the device except in one place:
  121.  
  122.   (* Return True, if there is a keyboard character waiting. *)
  123.   FUNCTION Char_Waiting : Boolean ;
  124.  
  125.     CONST
  126.       keyboard = 2 ;   (* Device number of the keyboard. *)
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. Character I/O                                                           Page 3
  137.  
  138.     FUNCTION bconstat( device : Integer ) : Boolean ;
  139.       BIOS( 1 ) ;
  140.  
  141.     BEGIN
  142.       Char_Waiting := bconstat( keyboard ) ;
  143.     END ;
  144.  
  145.  
  146. Besides character input and input status, you also need  to  be  able  to  put
  147. characters to character devices.  The following routines allow those actions:
  148.  
  149. Write a character to the standard output.
  150.  
  151. PROCEDURE conout( c : Integer ) ;
  152.   GEMDOS( 2 ) ;
  153.  
  154. This  call  puts  a  character  to  the  standard  output device (normally the
  155. screen).  The effect is identical to Writeing characters to the standard  file
  156. Output.  You should only use this call from a TOS application.
  157.  
  158. Put character to character-oriented device.
  159.  
  160. PROCEDURE bconout( device, c : integer ) ;
  161.   BIOS( 3 ) ;
  162.  
  163. This  routine  writes  a  single  character  to  the specified device.  If the
  164. device's output buffer is full, the routine will wait until the  character  is
  165. actually  placed  in  the  buffer.   If you don't want to wait for output, you
  166. should call bcostat first, to determine that the device is  ready  to  receive
  167. the next character.
  168.  
  169. Character-oriented device output status.
  170.  
  171. FUNCTION bcostat( device : Integer ) : Boolean ;
  172.   BIOS( 8 ) ;
  173.  
  174. This  routine  checks  to  see whether the specified device is ready to accept
  175. another character.  It returns True, if the device is ready  to  receive,  and
  176. False  otherwise.   If the ST is powered up while the printer is off-line, the
  177. hardware does not detect the off-line condition.  The bcostat call will return
  178. True, in this case, even though the printer is not ready to accept  data.   As
  179. soon as the printer is turned on-line again, the status is correct.
  180.  
  181. Get status of standard print device.
  182.  
  183. FUNCTION c_prnos : Boolean ;
  184.   GEMDOS( 17 ) ;
  185.  
  186. This  call  returns  True  if  the  printer is available to accept characters,
  187. False otherwise.  However, as mentioned in the section about the bcostat  BIOS
  188. call, the ST hardware cannot detect an off-line condition if the ST is powered
  189. up  while  the  printer  is off-line.  In this situation, the c_prnos function
  190. will erroneously return True.
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. Character I/O                                                           Page 4
  203.  
  204. Check output status of auxilliary device (RS232).
  205.  
  206. FUNCTION c_auxos : Boolean ;
  207.   GEMDOS( 19 ) ;
  208.  
  209. This routine returns True, if the standard  auxilliary  device  (normally  the
  210. RS232  port) is ready to accept data, and False, otherwise.  If the auxilliary
  211. device is the RS232 port, this call will only return False if the RTS/CTS flow
  212. control method is used, and CTS goes to a false condition.
  213.  
  214.  
  215. Press <CR> to continue: